<template>
	<view class="content pc-tou-gao " >
		<view class="scroll-fix" >

		
			<view class="d-kuan-juzhong ">
				<!--头部-->
				<view class="d-kuan pc-dingbu ">
					<DToubu 
					@login-success="handleLoginSuccess" 
					@logout-success="handleLogout"
					:dengluxianshi="denglu_xianshi"
					@www-data="wwwdataget"
					@update-dengluxianshi="handleUpdateDengluxianshi"
					></DToubu>
					
				</view>
				


				<!--头部-->
				<!--下面内容-->
				<view class="d-kuan d-clear">
					<uv-row customStyle="margin-bottom: 10px" :gutter="10">
						<!-- #ifdef H5 -->
						<uv-col span="2" class="pc-yincang">
							<!--左边导航-->
							<view class="d-daohang d-you-10 pc-yincang d-y-gundong d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight}">
								<view class="d-daohang-5 " >
									<Ddaohang 
									@denglu-fabu="denglu_fabu"
									
									></Ddaohang>
								</view>
							</view>
						</uv-col>
						<!-- #endif -->

						<uv-col :span="kuan_shu">
							
							<view class="d-shang-50">
								<view class="d-waikuang-20-0 d-beijing-bai ">
									<!--头部-->
										<Dfanhui
										title="会员套餐"
										>

									</Dfanhui>
									<view class="page">
										<view class="d-kuan pc-neikuang-20-list" >

											<view class="d-kuan margin-top-sm padding-lr-xs d-xia-10">
												<view class="bg-brown hei radius-lg shadow-blur">
													<view class="flex padding-tb-sm padding-lr-sm justify-between">
														<view class="d-zuo d-xia-10">
															<view>
																<view class=" d-jiacu d-wenzi-16 d-shangxia-10" style="margin-left: 30px;">
																	<text v-for="(list,index) in u_data.group_data" :key="index">{{ list.group_name }}</text>
																</view>
																<view class="" style="margin-left: 30px;font-size: 28rpx;">
																	<text v-for="(list,index) in u_data.group_data" :key="index">{{ list.etime ? '到期时间：' + list.etime : '永久会员' }}</text>
																</view>
															</view>
														</view>
														<view class="d-you d-juzhong d-xia-10"  style="margin-right: 30px;">
															<view>
																<!--引入图标vip.png,图标大小20px-->
																<image src="/static/img/vip.png" class="d-kuang-20 d-shangxia-juzhong "  style="margin-left: 30px;height: 60px;width: 60px;"></image>
															</view>
														
														</view>
													</view>
												</view>
											</view>
										</view>

										<view class="option d-shang-20">
											<view class="d-kuan d-gao-80"></view>
											<!--view class="option-title">会员套餐</view-->
											<view class="option-list">
												<view :class="'option-item ' + ((current !== null && Number(k) === Number(current)) ? 'option-selected' : '')" v-for="(v, k) in u_data.vip" :key="k" @click="change(k, v.price)">
													<text>{{v.name}}</text>
													<text  style="font-size: 34rpx;">￥{{v.price}}</text>
													<text v-if="v.days ==0">永久</text>
													<text v-else>{{v.days}} 天</text>
													<!--view class="option-item-line"></view-->
												</view>
											</view>
											<view v-if="h5_weixin==0">
	
												<view class="option-botton" @click="pay()">立即开通</view>
											</view>
											<view v-else>
												<view v-if="u_data && u_data.bang_weixin == 1">
													<view class="option-botton" @click="pay()">立即开通</view>
												</view>
												<view v-else>
													<button  v-on:click="bang_weixin()" class="btSubmit" :style="{ backgroundColor: chongzhi_title_zhi === 1 ? '#fd4542' : '#5a2e5d' }">
														先绑定 微信后充值
													</button>
												</view>
											</view>
											

											

											<view class="d-kuan d-gao-80"></view>
										</view>


										<view class="table">
											<!--view class="td ">
												<view style="width: 120px !important;">权限</view>
												<view v-for="(list,index) in u_data.vip" :key="index">{{ list.name }}</view>
											</view-->
											<view class="td" v-for="(v, k) in advantages" :key="k">
												<view >{{v.name}}</view>
												<view  v-for="(list,index) in u_data.vip" :key="index" :style="(current !== null && Number(index) === Number(current)) ? 'background-color:#e9ebeb;color:#fff;' : 'background-color:#fdffff;color:#333;'">
													<!-- 根据当前套餐的设置展示：当 v.ming 为 'score' 时显示数值，否则显示勾/叉 -->
													<view v-if="k == 0">
														{{ list.name  }}
													</view>
													<view v-else-if="v.ming === 'shuliang'">
														{{ list.setting && list.setting.level && list.setting.level.quan_shuliang }} 个
													</view>
													<view v-else-if="v.ming === 'yongjin'">
														{{ list.setting && list.setting.level && list.setting.level.quan_yongjin }} %
													</view>

													<view v-else-if="v.ming === 'score'">
														{{ (list && list[v.ming] != null) ? list[v.ming] : '-' }}
													</view>

													<view v-else>
														<image src="/static/img/ok.png" v-if="list && list.setting && list.setting.level && (Number(list.setting.level[v.ming]) === 1 || list.setting.level[v.ming] === true)"></image>
														<image src="/static/img/no.png" v-else></image>
													</view>
													
													
												</view>						
											</view>
										</view>
									</view>																																																						
								</view>

							</view>								
							<view class="pc-neikuang-20-list" >
								<view class="d-neikuang-40 d-beijing-baise d-yuanjiao-10 d-shang-10 d-clear">
									<view class="d-kuan d-shang-20 d-clear">
										<view class="d-kuan d-juzhong d-jiacu d-shangxia-10">套餐说明</view>
										<uv-parse :content="wwwData && wwwData.setting && wwwData.setting.quan_taocan_shuoming" :lazy-load="true" :selectable="true"></uv-parse>
									</view>
								</view>
							</view>
							
							<!--头部背景-->
							
							
						</uv-col>
						<!-- #ifdef H5 -->
						<uv-col span="3" class="pc-yincang">
							<view class="d-daohang d-you-10 pc-yincang d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight}">
								<view class="d-you-kuang">
									
								</view>
							</view>
						</uv-col>
						<!-- #endif -->
					</uv-row>

					

				</view>
				<!--下面内容-->


			</view>

			<view class="d-clear"></view>
		
		</view>
		<Dzhifu
			:show="show_zhifu"
			:payType="payType_zhifu"
			:jine="jine"
			:payid="payid"
			@close="show_zhifu = false"
			@uidapi="getu_api"
		></Dzhifu>
		
		

	</view>
</template>

<script>
    import Api from '@/utils/api.js'; 
	import QuanApi from '@/utils/quan_api.js';
	import UApi from '@/utils/u_api.js';
	import { getRequest,postRequest } from '@/utils/wxRequest.js';
    //引入组件 d-toubu
    import DToubu from '@/components/d-toubu/d-toubu.vue'
	import Ddaohang from '@/components/d-daohang/d-daohang.vue'
	import Dweibu from '@/components/d-weibu/d-weibu.vue'
	import Dfanhui from '@/components/d-fanhui/d-fanhui.vue'
	import Dzhifu from '@/components/d-zhifu/d-zhifu.vue'
	
	
	export default {
		data() {
			return {
				
				title: 'Hello',
				leftNavHeight: '500rpx', // 默认高度
                rightColWidth: '300px', // 默认宽度
				rightColLeft: '0px', // 添加这个属性
				
				erjidata:[],
				erjiindex:'',//当前激活的二级菜单索引
				activeIndex: -1, // 当前激活的一级菜单索引
				zhishi_tuijian_data:[], // 知识推荐数据
				zhishi_daohang_list:[], // 知识导航列表
				zhishi_list:[], // 知识列表
				haibao_data:[], // 海报数据
				imageSize: {
        		    width: 0,
        		    height: 0
        		},
				tubiaolist: 
				['integral', 'kefuv-ermai', 'coupon', 'gift', 'scan',
					'pause-circle', 'volume-off', 'email', 'list'
				],
				denglu_xianshi:0, // 登录显示

				tiezi_list:[], // 帖子列表

				currentPage: 1, //下拉加载
    			pageSize: 12, //下拉加载
    			isLoading: false, //下拉加载
    			noMoreData: false, //下拉加载
				
				kuan_shu: 7, //格大小
				uid: '', // 用户ID - 初始化为空字符串，将在onLoad/onShow中设置
				swiperHeight: '250',
				gao: '20', //图片高度
				
				quan_data:[],
				
				shenhe_shu:0,//审核帖子数量
				u_data:[], // 用户信息
				dataLoaded: false,
			
				guanzhu_panduan:0,
				options: [

				],
				advantages: [
					{name: '权限', normal: 0, vip: 1,ming:'quanxian'},
					{name: '加入圈子', normal: 0, vip: 1,ming:'jiaru'},
					{name: '阅读帖子', normal: 0, vip: 1,ming:'tiezi'},
					{name: '赠送积分', normal: 0, vip: 1,ming:'score'},
				],
				current: null, // 当前选中套餐（默认不选）
				
				zhifuerweima: {}, // 支付二维码数据
				show: false,
				show_zhifu:false, // 支付弹窗
				payType_zhifu:'weixin', // 支付类型 1是支付宝，2是微信
				jine:0, // 金额
				price: 0, // 当前选中套餐价格
				payid:'', // 支付ID
				h5_weixin:0, // 判断是否在微信浏览器 并且是h5页面
				wwwData: {}, // 网站数据



			}
		},
		components: {
  		    DToubu,
			Ddaohang,
			Dweibu,
			Dfanhui,
			Dzhifu,
  		},
		mounted() {
			// 确保在组件挂载后更新uid
			// console.log('Component mounted, checking uid...');
			const storeUid = this.$store.state.memberuid;
			if (storeUid && !this.uid) {
				this.uid = storeUid;
				// console.log('UID set from store in mounted:', this.uid);
			}
			
    	    this.setLeftNavHeight();
			this.getRightColWidth(); // 添加这行
    	    // 添加窗口大小变化监听
			// #ifdef H5
    	    window.addEventListener('resize', this.setLeftNavHeight);
			window.addEventListener('resize', this.getRightColWidth); // 添加窗口大小变化监听
			// #endif
			var e = this;
			//this.onImageLoad(e);
    	},
    	beforeDestroy() {
    	    // 移除监听
			// #ifdef H5
    	    window.removeEventListener('resize', this.setLeftNavHeight);
			window.removeEventListener('resize', this.getRightColWidth); // 添加这行
			// #endif
    	},
		onShow() {
			// 检查是否在微信浏览器 并且是H5
			this.isH5Weixin();
			// console.log('Component shown, updating uid...');
			const storeUid = this.$store.state.memberuid;
			// console.log('Store memberuid:', storeUid);
			this.uid = storeUid;
			// console.log('UID set in onShow:', this.uid);

			if(!storeUid){
				// console.log('No uid in store, showing login prompt');
				this.denglu_xianshi = 1;
				this.godenglu(); // 暂时注释掉自动跳转，便于调试
			}

			//this.getShenhe_shu_api();
			
		},
		onLoad(e) {
			// console.log('Component loaded with params:', e);
			// 优先使用路由参数中的uid
			if (e && e.uid) {
				this.uid = e.uid;
				// console.log('UID set from route params:', this.uid);
			} else {
				// 如果路由参数中没有uid，则从store获取
				const storeUid = this.$store.state.memberuid;
				if (storeUid) {
					this.uid = storeUid;
					// console.log('UID set from store in onLoad:', this.uid);
				} else {
					// console.log('No uid available in route params or store');
				}
			}
			
			// 只有在有uid的情况下才调用API
			if (this.uid) {
				this.getu_api();
			} else {
				console.warn('Cannot call getu_api: uid is not available');
			}
			
		},
		computed: {
		  yidenglu() {
		    return (this.$store.state.memberuid && this.$store.state.keycode) ? 1 : 0;
		  },
		  touxiang() {
		    return this.$store.state.member? this.$store.state.member.avatar : '';
		  },
		  name1() {
		    return this.$store.state.member? this.$store.state.member.name : '';
		  },
		  pc() {
		    return this.$store.state.kuan.pc;
		  },
		},
		onReachBottom() {
  			//this.onReachBottom(); //下拉加载分页
  		},

		methods: {
			// 判断是否在微信浏览器 并且是H5：是则返回h5_weixin=1，否则返回h5_weixin=0
			isH5Weixin() {
				// #ifdef H5
				try {
					const ua = (typeof window !== 'undefined' && window.navigator) ? window.navigator.userAgent.toLowerCase() : '';
					const isWeixin = ua.indexOf('micromessenger') !== -1; // 微信内置浏览器
					const isMobile = /mobile|android|iphone/.test(ua);     // 手机端（不含iPad/PC）
					this.h5_weixin = (isWeixin && isMobile) ? 1 : 0;
					return this.h5_weixin;
				} catch (e) {
					this.h5_weixin = 0;
				}
				// #endif
				this.h5_weixin = 0;
				return 0;
			},
			//图片
			onImageLoad(e, index) {
				// 获取系统信息
				const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowHeight = systemInfo.windowWidth;
				if(windowHeight >=920){
					var gao = 30;
					
				} else {
					var gao = 0;
				}


				this.$nextTick(() => {
        		    const query = uni.createSelectorQuery().in(this);
        		    query.select('#tupian-'+index).boundingClientRect(data => {
        		        if (data && data.width > 0 && data.height > 0) {
        		            this.$set(this.haibao_data[index], 'imageSize', {
        		                width: data.width,
        		                height: data.height + gao
        		            });
							// console.log('图片尺寸:', this.haibao_data[index].imageSize);
        		        } else {
        		            console.warn(`图片${index}尺寸获取失败`);
        		            this.$set(this.haibao_data[index], 'imageSize', {
        		                width: 300,
        		                height: 200
        		            });
        		        }
        		    }).exec();
        		});

    		},
			getRightColWidth() {
				// 获取系统信息
				//const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    //const windowWidth = systemInfo.windowWidth;
				var d = this;

                this.$nextTick(() => {
				if(this.pc){
					d.gao = 20;
					d.kuan_shu = 7;
					d.swiperHeight = '250';
				} else {
					d.gao = 10;
					d.kuan_shu = 12;
					d.swiperHeight = '120';

				}
				// console.log('窗口高度:', windowWidth);

                 const query = uni.createSelectorQuery().in(this);
                 query.select('#youbiankuan').boundingClientRect(rect => {
                   if (rect) {
                     /*this.rightColWidth = `${rect.width+20}px`;
                     // console.log('右侧列宽度:', this.rightColWidth);*/
					 	this.rightColWidth = `${rect.width-80}px`;
                    	this.rightColLeft = `${rect.left}px`; // 计算左侧位置
                    	// console.log('右侧列位置:', this.rightColWidth);
                   }
                 }).exec();
               });
            },

			
			
			setLeftNavHeight() {
        	    // 获取系统信息
        	    const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowHeight = systemInfo.windowHeight;
        	    const headerHeight = 70; // 头部高度估计值
        	    const calculatedHeight = windowHeight - headerHeight;
				
        	    // 设置左边导航高度
        	    this.leftNavHeight = `${calculatedHeight}px`;
        	},
			
			
			handleLoginSuccess() {
  			  this.$forceUpdate();
  			},

			denglu_fabu(){
				if(this.yidenglu == 0){
					this.denglu_xianshi = 1;
					
				} else {
					this.denglu_xianshi = 0;
						
				}
				
				// console.log('发布登录',this.denglu_xianshi);
				
			},
			// 更新判断是否登录
			handleUpdateDengluxianshi(value) {
			  this.denglu_xianshi = value;
			  
			  // console.log('关闭登录',this.denglu_xianshi);
			},
			// 退出登录
			handleLogout() {
 			  this.godenglu(); // 暂时注释掉自动跳转，便于调试
 			},

			//个人信息
			getu_api(){
				// console.log('Calling getu_api with uid:', this.uid);
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				const data = {
						uid: this.uid,
						api_auth_uid: this.uid,
						api_auth_code: keycode,
					}
				var get_data = getRequest(UApi.getU(),data);
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						if(this.uid){
							//this.u_data = res.data.data.wo;
						} else {
							//this.u_data = res.data.data.u;
						}
						this.u_data = res.data.data;
						//this.u_data = res.data.data;
						this.dataLoaded = true;
						// 默认不选中任何套餐，等待用户点击
						this.current = null;
						
					}
				})

			},
			//跳转个人信息
			godenglu(){
				//保持url到缓存，名称是u_url
				uni.setStorageSync('go_url', this.$route.fullPath);
				uni.navigateTo({
					url: '/pages/u/denglu',
				})
			},

			tuichu(){
				uni.showToast({
					title: "退出成功",
					icon: 'success',
				})

				uni.removeStorageSync('userInfo');
				uni.removeStorageSync('memberuid');
				uni.removeStorageSync('keycode');
				uni.removeStorageSync('member');
				// 通过 mutations 更新 Vuex 状态
				this.$store.commit('setMember', {});
    			this.$store.commit('setMemberUid', '');
    			this.$store.commit('setKeycode', '');
				//this.yidenglu = 0;
				// 触发退出事件
				this.$emit('logout-success');
				//退出跳转到首页
				uni.reLaunch({ url: "/pages/index/index" });
			},
			url(urls){
				uni.navigateTo({
					url: '/pages/u/'+urls,
				})
			},
			change(k, price){
				const nk = (typeof k === 'string' && /^\d+$/.test(k)) ? Number(k) : k;
				this.current = nk;
				// 可选：把价格赋给充值金额，以便后续支付展示
				this.jine = price;
				this.price = price;
			},
			pay(){
				// 弹出提示 加载中...
                uni.showToast({ title: '加载中...', icon: 'loading', duration: 3000 });
					// 判断 this.current 为空的时候 弹出提示
					if (this.current === null || this.current === undefined) {
						uni.showToast({
							image: '/static/img/no.png',
							title: '请选择套餐'
						});
						return;
					}
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				var pays = '';
				if(this.u_data && this.u_data.wo && this.u_data.wo.money >= this.price){
					var pays = 'finecms';
				} else {
					var pays = 'weixin';
				}
				// 兼容数组/对象两种vip结构，优先使用套餐的id
				const vipList = this.u_data && this.u_data.vip;
				let vip_id = this.current;
				if (Array.isArray(vipList)) {
					const item = vipList[this.current];
					if (item && item.id != null) vip_id = item.id;
				} else if (vipList && typeof vipList === 'object') {
					const item = vipList[this.current] || vipList[String(this.current)];
					if (item && item.id != null) vip_id = item.id;
				}
				var datas = "is_ajax=1&_token=&pay_type="+pays;
				var post_data = postRequest(UApi.postVip(uid,keycode,vip_id),datas);
				var res_data;
				post_data.then(duixin_data => {
					res_data = duixin_data;
					if(res_data.data.code >= 1){
						// 弹出余额 支付提示 确认和 取消按钮
						if(this.u_data && this.u_data.wo && this.u_data.wo.money >= this.price){
							uni.showModal({
								title: '余额支付',
								content: '您当前余额为'+this.u_data.wo.money+'元，是否使用余额支付？',
								success: (res) => {
									if (res.confirm) {
										// 确认使用余额支付
										this.huanqiPay(res_data);
									} else if (res.cancel) {
										// 取消支付
										console.log('用户取消了余额支付');
									}
								}
							});
						} else {
							this.huanqiPay(res_data);
						}
						
					} else {
						uni.showToast({
							icon: 'none',
							title: res_data.data.msg || '开通失败'
						});
					}
					
					
					/*if(res.data.code == -1){
						uni.showToast({
							icon: 'none',
							title: '没有开放发帖'
						});
					}*/
				})
				
			},
			// 拉起支付
			huanqiPay(res) {
				//判断用户的金额是否大于等于套餐的金额
				var pays = '';
				if(this.u_data.wo && this.u_data.wo.money >= this.price){
					var pays = 'finecms';
				} else {
					var pays = 'weixin';
				}
				/*console.log('finecms',pays);
				console.log('finecms-price',this.price);
				console.log('finecms-money',this.u_data.wo && this.u_data.wo.money);*/
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				//
				var denglu = '&api_auth_uid='+uid+'&api_auth_code='+keycode;
				var data_zhi = res.data && res.data.data;
				// 把 data_zhi.value 的值变成正值
				data_zhi.value = Math.abs(data_zhi.value);
				//this.jine = res.value;
				var duixin = this; 
				// #ifdef H5
				const userAgent = navigator.userAgent.toLowerCase();
				if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android/.test(userAgent)) {
					// 移动端
					//判断是否在微信浏览器中
					if(/micromessenger/.test(userAgent)){
						// 微信浏览器中
						//console.log('移动端',userAgent) pay[mar0k]=recharge
						var h5datas = "is_ajax=1&pay[mark]="+ data_zhi.mid +"&pay[money]=" + data_zhi.value + "&pay[type]="+pays+"&pay[is_xcx]=1&h5=1";
						duixin.jine = data_zhi.value;
						duixin.payid = res.data && res.data.data && res.data.data.id;
						console.log('微信浏览器中payid1',duixin.payid);

					} else {
						// 非微信浏览器中
						if(this.u_data.wo && this.u_data.wo.money >= this.price){
						} else {
							duixin.jine = data_zhi.value;
							duixin.payid = res.data && res.data.data && res.data.data.id;
							console.log('非微信浏览器中payid1',duixin.payid);
							duixin.show_zhifu = true;
							return;
						}
					}
					
				} else {
					// pc端
					//console.log('PC端',userAgent)
					//var h5datas = "is_ajax=1&pay[mar0k]=recharge&pay[money]=" + data_zhi.value + "&pay[type]="+pays+"&pay[is_xcx]=1&h5=2";
					// 弹出 Dzhifu 组件
					if(this.u_data.wo && this.u_data.wo.money >= this.price){
					} else {
						duixin.show_zhifu = true;
						duixin.jine = data_zhi.value;
						duixin.payid = res.data && res.data.data && res.data.data.id;
						console.log('payid1',duixin.payid);
						return;
					}
				}
				// #endif
				//console.log('拉起支付',data_zhi.value); =recharge

				var datas = "is_ajax=1&pay[mark]="+ data_zhi.mid +"&pay[money]=" + data_zhi.value + "&pay[type]="+pays+"&pay[is_xcx]=1";
				var duixin = this; 
				// #ifdef MP
				var getPayidRequest = getRequest(Api.getPayid(data_zhi.id,datas,uid,keycode));
				// #endif
				// #ifdef H5
				var getPayidRequest = getRequest(Api.getPayid(data_zhi.id,h5datas,uid,keycode));
				// #endif
				getPayidRequest.then(response => {
					//console.log('finecms99',response);
					
                    
					if (response.data.code) {
						
						
						
						// #ifdef H5
							//duixin.getH5payzhifu(response.data.data,urldata);
							if(response.data.data && response.data.data.pc == 1){
								duixin.zhifuerweima = response.data.data;
								
								duixin.payid = res.data && res.data.data && res.data.data.id;
								duixin.show_zhifu = true;
								console.log('payid2',duixin.payid);
							} else {
								if(this.u_data.wo && this.u_data.wo.money >= this.price){
									// 余额支付
									duixin.yuePay(res);
									duixin.getu_api();
								} else {
									duixin.getWeixinMiyueData(response.data.data);
										
										
								}
							}
						// #endif
					    // #ifdef MP
						// 小程序
						if(this.u_data.wo && this.u_data.wo.money >= this.price){
							duixin.yuePay(res);
							duixin.getu_api();

						} else {
							wx.requestPayment({
								"timeStamp": response.data.data.timeStamp,
								"nonceStr": response.data.data.nonceStr,
								"package": response.data.data.package,
								"signType": "MD5",
								"paySign": response.data.data.paySign,
								"success":function(res){
									duixin.getMemberpay(res);
									duixin.getu_api();
									const targetUrl = uni.getStorageSync('goumai_jifen_url') || duixin.fanhuiurl;
									if (targetUrl && /^\/pages\/[^/]+\/[^/]+/.test(targetUrl)) {
										uni.navigateTo({ url: targetUrl });
									} else {
										// 兜底：无效或空的返回地址，跳转到首页
										uni.reLaunch({ url: '/pages/index/index' });
									}



								},
								"fail":function(res){
									//console.log(res);
									wx.showModal({
										showCancel: false,
										content: res.err_desc+"："+res.errMsg
									})
								}

							})


						}
						
						// #endif

					}  else {
						duixin.zhifuerweima = response.data.data;
						duixin.payid = response.data && response.data.data && response.data.data.id;
                        duixin.show_zhifu = true;
 						uni.showToast({
 							icon: 'none',
 							title: response.data.msg,
 							duration: 1000
 						});
					}
					
				})
				
				
				
			},
			// 拉起余额支付
			yuePay(res){
				console.log('余额支付res',res.data && res.data.data && res.data.data.id);
				var id = res.data && res.data.data && res.data.data.id;
				var duixin = this;
				var uid = this.$store.state.memberuid;
				var keycode = this.$store.state.keycode;
				var getYuepayRequest = getRequest(Api.getYuepay(uid,keycode,id));
				getYuepayRequest.then(response => {
					//console.log('余额支付',response);
					if (response.data.code) {
						// 弹出支付成功 + 图标
						uni.showToast({
							icon: 'success',
							title: '支付成功'
						});
						
					} else {
						uni.showToast({
							icon: 'none',
							title: response.data.msg || '开通失败'
						});
					}
				})
				
				
			},

			//拉起微信
			async getWeixinMiyueData(data){
				var duixin = this;
				// #ifdef H5
				try {
					await this.$ensureWxLoaded();
				} catch (e) {
					console.error('JSSDK加载失败：', e);
					uni.showToast({ title: '微信JSSDK加载失败', icon: 'none' });
					return;
				}
				// #endif
				// #ifdef H5
				const wxRef = window.wx || (window.duixin && window.duixin.$wx);
				if (!wxRef || typeof wxRef.config !== 'function') {
					console.error('微信JSSDK未正确加载：wxRef.config 不可用', wxRef);
					uni.showToast({ title: '微信JSSDK不可用', icon: 'none' });
					return;
				}
				// #endif
								var danqianurls = uni.getLaunchOptionsSync();
				//var danqianurls = '/'+danqianurls.path+'?id='+danqianurls.query.id;
				var danqianurls = '/'+danqianurls.path;
				
				const url = decodeURIComponent(window.location.href);
				var urljia = danqianurls;
				
				var getWeixinmiyueRequest = getRequest(Api.getWeixinfengxiangmiyue(url));
				 
				getWeixinmiyueRequest.then(response => {
					
					if (response.data.code == 1) {
						
						var weixin = response.data.data;
						//console.log('充值H5weixin',weixin);
						wxRef.config({
						  debug: false,//true
						  appId: weixin.appId,
						  timestamp: weixin.timestamp,
						  nonceStr: weixin.nonceStr,
						  signature: weixin.signature,
						  jsApiList: [
						    // 所有要调用的 API 都要加到这个列表中
						    
						    // 这里需要自己按微信文档来写参数
						    "updateAppMessageShareData", 
							"updateTimelineShareData",
							'checkJsApi', //判断当前客户端版本是否支持指定JS接口  
							'onMenuShareAppMessage', //分享接口  
							'getLocation', //获取位置  
							'openLocation', //打开位置  
							'scanQRCode', //扫一扫接口  
							'chooseWXPay', //微信支付  
							'chooseImage', //拍照或从手机相册中选图接口  
							'previewImage', //预览图片接口  
							'uploadImage' //上传图片  
						  ]
						});
						wxRef.ready(function () {
							//duixin.getPayzhifu(dataa,datab);
							//console.log('支付data',data); 
							
							// config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
							wxRef.checkJsApi({
								jsApiList: ['chooseWXPay'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
								success: function(res) {
									//console.log('支付res',res); 
								}
							});
							// 调用微信支付接口
							wxRef.chooseWXPay({
								timestamp: data.timeStamp,    // 时间戳
								nonceStr: data.nonceStr,      // 随机串
								package: data.package,        // 订单详情扩展字符串
								signType: 'MD5',                // 签名方式
								paySign: data.paySign,           // 签名
								success: function(res) {
									// 支付成功后的回调函数
									//duixin.getMemberpay(res);
									duixin.getu_api();
									// 返回会员页面
									 uni.navigateTo({ url: '/pages/wo/u' });
								},
								fail: function(res) {
									// 支付失败后的回调函数
									console.error('Payment failed', res);
									
									setTimeout(() => {
										uni.reLaunch({
											//url: '/pages/fail/fail'
										})
									}, 500)
								}
							})
							
						});
						wxRef.error(function(res){
						  //console.log('weixinres',res); 
						});
					} else {
					    duixin.setData({
							displaySwiper: "none"
					    });
					}
				});


			},
			// 先绑定 微信后充值
			bang_weixin(){
				uni.navigateTo({ url: '/pages/u/bangweixin' });
				
			},
			//站点设置
			wwwdataget(data){
				this.wwwData = data;
				// 仅修改第3个数据项（下标3）的名称："赠送" + jifen 原文
				const jifenRaw = (data && data.setting && typeof data.setting.jifen !== 'undefined') ? data.setting.jifen : '';
				if (Array.isArray(this.advantages) && this.advantages.length > 2 && this.advantages[3]) {
					this.advantages[3].name = `赠送${String(jifenRaw)}`;
				} else {
					// console.warn('advantages[3] 不存在，无法更新名称', this.advantages);
				}
				// console.log('wwwdata0000',data.setting.quan_moshi);
				if(data && data.setting && data.setting.quan_moshi==0){
					this.advantages = [
						{name: '权限', normal: 0, vip: 1, ming:'quanxian'},
						{name: '加入圈子', normal: 0, vip: 1, ming:'jiaru'},
						{name: '阅读帖子', normal: 0, vip: 1, ming:'tiezi'},
						{name: '赠送积分', normal: 0, vip: 1, ming:'score'},
						{name: '申请数量', normal: 0, vip: 1, ming:'shuliang'},
						{name: '佣金比例', normal: 0, vip: 1, ming:'yongjin'},
					];
				} else {
					this.advantages = [
						{name: '权限', normal: 0, vip: 1,ming:'quanxian'},
						{name: '加入圈子', normal: 0, vip: 1,ming:'jiaru'},
						{name: '阅读帖子', normal: 0, vip: 1,ming:'tiezi'},
						{name: '赠送积分', normal: 0, vip: 1,ming:'score'},
					];
				

				}
				//console.log('wwwdata',this.wwwData);
			},







		}
	}
</script>

<style lang="scss">
@import "./vip.scss";
/*引入css main.css*/

	.content {
		
		
		display: flex;
		flex-direction: column;
		/*align-items: center;*/
		
		background-color: #f3f3f3;
		
		margin-bottom: 0px;
		
		/*height: 100vh;*//* 添加全屏 */
		/*width: 100vw;*/ /* 添加全屏*/
		box-sizing: border-box;
		overflow-x: hidden;

		
		

	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	/* 屏幕宽度大于786px时隐藏uni-page-head */
    @media (min-width: 786px) {
        uni-page-head {
            display: none !important;
            opacity: 0 !important;
            height: 0 !important;
            visibility: hidden !important;
        }
    }
	/*.d-daohang{
		
		width: 600rpx;
	}*/
	/* 添加在style部分 */
	.d-daohang-zuo {
    position: fixed;
    left: 0;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #f5f5f5;
    z-index: 100;
	box-shadow: 2px 0 5px rgba(177, 177, 177, 0.1);
  }
  
  .d-daohang-you {
    position: fixed;
    left: 180rpx;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #fff;
    z-index: 100;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
  }                  
   
  .d-erji-item {
    height: 60rpx;
    line-height: 60rpx;
    padding: 0 20rpx;
   /* border-bottom: 1px solid #f0f0f0;*/
  }
  
  .d-erji-item:active {
    background: #f5f5f5;
  }
  .you-guding {
	position: fixed;
	top: 0; /* 根据头部高度调整 */
	/*box-shadow: -2px 0 5px rgba(0,0,0,0.1);*/
	transition: all 0.3s ease;
}
/* 大于786px时的样式 */
@media screen and (min-width: 1024px) {
	.d-bianhua-10 {
		padding: 30px;
	}
	.pc-zuo-520 {
		margin-left: 520rpx;
	}
	.you-guding {
		position: fixed;
			
		top: 60px; /* 根据头部高度调整 */
		/*box-shadow: -2px 0 5px rgba(0,0,0,0.1);*/
		transition: all 0.3s ease;
	}
		
	
}
	
</style>
